package cn.ulc.socket.weapp.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import cn.ulc.common.annotation.IgnoreAuth;
import cn.ulc.common.exception.PlatformException;
import cn.ulc.common.util.AliSmsUtil;
import cn.ulc.common.util.Result;
import cn.ulc.socket.weapp.model.param.UserSaveParam;
import cn.ulc.socket.weapp.service.UserServ;
import com.google.common.collect.Maps;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.BindingResult;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

@RestController
@RequestMapping(value = "/wechat/user")
public class UserController {

    private static final Log log = LogFactory.get();
    @Autowired
    UserServ userServ;
    @GetMapping("/index")
    public Result index(){
        return Result.success(userServ.loadIndex());
    }

    @PutMapping("")
    public Result update(@Validated @RequestBody UserSaveParam param, BindingResult result){
        if(result.hasErrors()) {
            log.error("修改个人信息参数有误",result.getFieldError().getDefaultMessage());
            return Result.fail(result.getFieldError().getDefaultMessage());
        }
        return Result.success(userServ.update(param));
    }


}
